package process0.gui;

import org.antlr.runtime.ANTLRStringStream;
import org.antlr.runtime.CharStream;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.RecognitionException;
import org.antlr.runtime.TokenStream;
import org.antlr.runtime.tree.CommonTreeNodeStream;

import process0.gen.Process0Lexer;
import process0.gen.Process0Parser;
import process0.gen.Process0Parser.process_return;
import process0.gen.Process0Walker1;
import process0.visitor.Visitor;
import process0.visitor.VisitorImpl;
import process0.visitor.VisitorViewWorklowImpl;

public class Interpreter implements InputDev {

	public void translate(String input) throws RecognitionException {
		Visitor visitor = new VisitorImpl();
		foo(input, visitor);

	}

	public void showWorkflow(String input) throws RecognitionException {
		Visitor visitor = new VisitorViewWorklowImpl();
		foo(input, visitor);
	}

	private void foo(String input, Visitor visitor) throws RecognitionException{
		CharStream charStream = new ANTLRStringStream(input);
		Process0Lexer lexer = new Process0Lexer(charStream);
		TokenStream tockenStream = new CommonTokenStream(lexer);
		Process0Parser parser = new Process0Parser(tockenStream);
		process_return evaluator = parser.process();
		CommonTreeNodeStream stream = new CommonTreeNodeStream(
				evaluator.getTree());
		Process0Walker1 walker = new Process0Walker1(stream);
		process0.ast.Process process = walker.process();
		process.accept(visitor);

	}
}
